package cn.cloudplug.instar_ec.main.base;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.AppCompatImageView;
import android.support.v7.widget.AppCompatTextView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.cloudplug.core.util.MyUtil;
import cn.cloudplug.instar_ec.R;
import cn.cloudplug.instar_ec.R2;

/**
 * Created by pc on 2018/2/5.
 */

public abstract class BackDelegate extends InstarDelegate {

    @BindView(R2.id.tv_title)
    AppCompatTextView mTitle;
    @BindView(R2.id.iv_bg)
    AppCompatImageView iv_bg;

    @OnClick(R2.id.ll_back)
    public void back(){
        getSupportDelegate().pop();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.delegate_back,container,false);
        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState); Object o=setContent();
        View v=null;
        if(o instanceof Integer){
            v=getLayoutInflater().inflate((Integer) o,null);
        }else if(o instanceof View){
            v= (View) o;
        }else{
            throw new ClassCastException("type of setLayout() must be int or View!");
        }
        ((RelativeLayout)view.findViewById(R.id.content)).addView(v,RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.MATCH_PARENT);
        mUnbinder= ButterKnife.bind(this,view);
        onBindView(savedInstanceState,view);
        MyUtil.blur(MyUtil.loadBitmapFromViewBySystem(getActivity().getWindow().getDecorView()),iv_bg,15);
    }

    public void setTitle(String title){
        mTitle.setText(title);
    }

}
